package leetcode.median;

public class $547_FindCircleNum {
    public int findCircleNum(int[][] isConnected) {
        int n = isConnected.length;
        boolean[] vis = new boolean[n];
        int ans = 0;
        for (int i = 0;i < n;i++) {
            if (!vis[i]) {
                // dfs
                dfs(isConnected, vis, i, n);
                ans++;
            }
        }
        return ans;
    }

    private void dfs(int[][] isConnected, boolean[] vis, int curCity, int n) {
        for (int i = 0;i < n;i++) {
            if (!vis[i] && isConnected[curCity][i] == 1) {
                vis[i] = true;
                dfs(isConnected, vis, i, n);
            }
        }
    }
}
